﻿using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using Telerik.Web.UI;

public partial class ModalWindow : System.Web.UI.Page
{
    protected string GUID
    {
        get
        {
            if (Request["guid"] == null)
            {
                throw new NotSupportedException("GUID missing");
            }
            return Request["guid"];
        }
    }
    protected Dictionary<String, Object> data
    {
        get
        {
            return ViewState["data"] as Dictionary<String, Object>;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void AjaxPanel_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {
        JavaScriptSerializer jsser = new JavaScriptSerializer();
        Dictionary<String, Object> dictArgs = jsser.Deserialize<Dictionary<String, Object>>(e.Argument);
        Dictionary<String, Object> dictData = (Dictionary<String, Object>)dictArgs["data"];
        ViewState["data"] = dictData;
        UpdateView();
    }
    private void UpdateView()
    {
        LblTime.Text = data["someString"] + " - " + DateTime.Now.ToString();
        newMoney.Value = Convert.ToDouble(data["someMoney"]);
    }
    protected void RadButton_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
        if (newMoney.Value < 50.5)
        {
            LblTime.Text = "<b>Enter Number bigger <span style='color:red;'>50.5</span></b> - " + DateTime.Now.ToString();
        }
        else
        {
            RadAjaxManager.GetCurrent(this.Page).ResponseScripts.Add("submitChanges('" + newMoney.Value.ToString() + "');");
        }
    }    
}
